package com.meowcook.mapper;

import com.meowcook.pojo.dto.RecipeAddDTO;
import com.meowcook.pojo.dto.RecipeDTO;
import com.meowcook.pojo.po.Recipe;
import com.meowcook.pojo.vo.RecipeDetailVO;
import com.meowcook.pojo.vo.RecipePartIVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28792
 * Date: 2025-05-15
 * Time: 18:59
 */
@Mapper(componentModel = "spring")
public interface RecipePojoMapper {
    RecipePojoMapper INSTANCE = Mappers.getMapper(RecipePojoMapper.class);

    @Mappings({
            @Mapping(source = "boardId", target = "boardId"),
            @Mapping(source = "name", target = "name"),
            @Mapping(source = "difficulty", target = "difficulty"),
            @Mapping(source = "servings", target = "servings"),
            @Mapping(source = "tips", target = "tips"),
            @Mapping(target = "coverImage", source = "coverImage")
    })
    Recipe toPO(RecipeAddDTO recipeAddDTO);

    @Mappings({
            @Mapping(source = "id", target = "id"),
            @Mapping(source = "boardId", target = "boardId"),
            @Mapping(source = "name", target = "name"),
            @Mapping(source = "difficulty", target = "difficulty"),
            @Mapping(source = "servings", target = "servings"),
            @Mapping(source = "tips", target = "tips"),
            @Mapping(target = "coverImage", source = "coverImage")
    })
    Recipe toPO(RecipeDTO recipeDTO);

    @Mappings({
            @Mapping(source = "id", target = "id"),
            @Mapping(source = "userId", target = "userId"),
            @Mapping(source = "boardId", target = "boardId"),
            @Mapping(source = "name", target = "name"),
            @Mapping(source = "coverImage", target = "coverImage"),
            @Mapping(source = "likeCount", target = "likeCount"),
            @Mapping(source = "collectCount", target = "collectCount"),
            @Mapping(source = "commentCount", target = "commentCount"),
            @Mapping(source = "author.id", target = "author.id"),
            @Mapping(source = "author.nickname", target = "author.nickname"),
            @Mapping(source = "author.avatarUrl", target = "author.avatarUrl"),
            @Mapping(source = "author.isAdmin", target = "author.isAdmin")
    })
    List<RecipePartIVO> toPartIVO(List<Recipe> recipes);

    @Mappings({
            @Mapping(source = "id", target = "id"),
            @Mapping(source = "userId", target = "userId"),
            @Mapping(source = "boardId", target = "boardId"),
            @Mapping(source = "name", target = "name"),
            @Mapping(source = "coverImage", target = "coverImage"),
            @Mapping(source = "description", target = "description"),
            @Mapping(source = "difficulty", target = "difficulty"),
            @Mapping(source = "tips", target = "tips"),
            @Mapping(source = "servings", target = "servings"),
            @Mapping(source = "likeCount", target = "likeCount"),
            @Mapping(source = "collectCount", target = "collectCount"),
            @Mapping(source = "commentCount", target = "commentCount"),
            @Mapping(source = "createTime", target = "createTime"),
            @Mapping(source = "author.id", target = "author.id"),
            @Mapping(source = "author.nickname", target = "author.nickname"),
            @Mapping(source = "author.avatarUrl", target = "author.avatarUrl"),
            @Mapping(source = "author.recipeCount", target = "author.recipeCount"),
            @Mapping(source = "author.fansCount", target = "author.fansCount"),
            @Mapping(source = "author.bio", target = "author.bio"),
            @Mapping(source = "author.isAdmin", target = "author.isAdmin"),
    })
    RecipeDetailVO toDetailVO(Recipe recipe);
}
